home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr47 / sptdemo.zip / TAPUNTE.PRG < prev    next >
Text File  |  1995-02-28  |  9KB  |  306 lines

  1. // ----------------------------------------------------------------------------
  2. // (c) 1,994 Juan Miguel Sosso Prieto - Todos los derechos reservados
  3. // Autor...: Juan Miguel Sosso
  4. // Proyecto: Contabilidad Personal
  5. // Módulo..: Mantenimiento de Apuntes
  6. // Fecha...: Mon  16-05-94
  7. // Hora....: 10:37:31
  8.  
  9. #include "inkey.ch"
  10. #include "sptools.ch"
  11. #include "tags.ch"
  12.  
  13. // ----------------------------------------------------------------------------
  14.  
  15. proc ManApuntes()
  16.  
  17.    local oBrw
  18.    local oMenu
  19.    local oItem
  20.  
  21.    DEFINE MENU oMenu AT MaxRow()
  22.       MENUITEM " &Modificar "  ACTION EditApunte( oBrw )
  23.  
  24.       MENUITEM " &Añadir "     ACTION AddApunte( oBrw )
  25.       MENUITEM oItem PROMPT " &Filtrar " ;
  26.                                ACTION FilApunte( oBrw, oItem )
  27.       MENUITEM " &Listado "    ACTION LisApunte()
  28.       MENUITEM " &Eliminar "   ACTION Eliminar( oBrw )
  29.       MENUITEM " &Salir "      ACTION .t.
  30.    END MENU
  31.  
  32.    oMenu:lOpened = .f.
  33.  
  34.    DEFINE BROWSE oBrw SIZE MaxRow() - 1, 80 ALIAS Apunte ;
  35.           TITLE "APUNTES CONTABLES"
  36.       COLUMN "FECHA"       DATA Apunte->dFECHA
  37.       COLUMN "GRUPO"       DATA Left( cGrupoDesc(), 18 )
  38.       COLUMN "DESCRIPCION" DATA Apunte->cDESC
  39.       COLUMN "INGRESO"     DATA Transform( Apunte->nINGRESO, "@Z9,999,999" )
  40.       COLUMN "GASTO"       DATA Transform( Apunte->nGASTO, "@Z9,999,999" )
  41.  
  42.       ON DBLCLICK          DO EditApunte( oBrw )
  43.    END BROWSE
  44.  
  45.    Apunte->( OrdSetFocus( "Fecha" ) )
  46.    oBrw:GoBottom()
  47.  
  48.    ACTIVATE BROWSE oBrw MENUBAR oMenu ACTION DispFoot()
  49.    Apunte->( DbClearFilter() )
  50.  
  51. return
  52.  
  53. // ----------------------------------------------------------------------------
  54.  
  55. static proc EditApunte( oBrw )
  56.  
  57.    local GetList := {}
  58.    local aField  := {}
  59.    local oWnd
  60.  
  61.    DEFINE WINDOW oWnd SIZE 13, 49 TITLE "APUNTE"
  62.    ACTIVATE WINDOW oWnd
  63.  
  64.    Apunte->( SaveFields( aField ) )
  65.  
  66.    @ 2,  3 SAY "Fecha......:" GET Apunte->dFECHA ;
  67.                               MESSAGE "Fecha del apunte"
  68.    @ 4,  3 SAY "Grupo:"       GET Apunte->nGRUPO VALID lDispGrupo() ;
  69.                               MESSAGE "Grupo contable al que pertenece el apunte - F6 acceso a tabla"
  70.    if lDispGrupo()
  71.       Grupo->nINGRESO -= Apunte->nINGRESO
  72.       Grupo->nGASTO   -= Apunte->nGASTO
  73.    endif
  74.  
  75.    @ 6,  3 SAY "Descripción:" GET Apunte->cDESC ;
  76.                               MESSAGE "Concepto del apunte"
  77.    @ 8,  3 SAY "Ingreso....:" GET Apunte->nINGRESO ;
  78.                               MESSAGE "Cantidad a ingresar"
  79.    @ 8, 28 SAY "Gasto....:"   GET Apunte->nGASTO ;
  80.                               MESSAGE "Cantidad a descontar"
  81.  
  82.    @ 10, 20 BUTTON "  &Aceptar  "  ACTION BTN_OK ;
  83.                                    MESSAGE "Grabar el apunte"
  84.    @ 10, 34 BUTTON "  &Cancelar  " ACTION BTN_CANCEL ;
  85.                                    MESSAGE "Descartar las modificaciones"
  86.  
  87.    SetKey( K_F6, { || BuscaGrupo() } )
  88.    READ
  89.    SetKey( K_F6, nil )
  90.  
  91.    if LastKey() == K_ESC
  92.       Apunte->( RestFields( aField ) )
  93.    else
  94.       Config->nINGRESO -= aField[ Apunte->( FieldPos( "nINGRESO" ) ) ]
  95.       Config->nGASTO   -= aField[ Apunte->( FieldPos( "nGASTO" ) ) ]
  96.       Config->nINGRESO += Apunte->nINGRESO
  97.       Config->nGASTO   += Apunte->nGASTO
  98.  
  99.       if ! Empty( Apunte->nGRUPO )
  100.          Grupo->nINGRESO += Apunte->nINGRESO
  101.          Grupo->nGASTO   += Apunte->nGASTO
  102.       endif
  103.       oBrw:RefreshAll()
  104.    endif
  105.  
  106.    DEACTIVATE WINDOW oWnd
  107.  
  108. return
  109.  
  110. // ----------------------------------------------------------------------------
  111.  
  112. static proc AddApunte( oBrw )
  113.  
  114.    local nActual := Apunte->( RecNo() )
  115.  
  116.    Apunte->( DbAppend() )
  117.    Apunte->dFECHA = Date()
  118.    EditApunte( oBrw )
  119.  
  120.    if LastKey() == K_ESC
  121.       Apunte->( DbDelete() )
  122.       Apunte->( DbGoto( nActual ) )
  123.    else
  124.       oBrw:GoBottom()
  125.       oBrw:RefreshAll()
  126.    endif
  127.  
  128. return
  129.  
  130. // ----------------------------------------------------------------------------
  131.  
  132. static proc FilApunte( oBrw, oItem )
  133.  
  134.    local nComo
  135.    local cFiltro  := Space( Len( Apunte->cDESC ) )
  136.    local nGrupo
  137.  
  138.    if oItem:cItem == " &Filtrar "
  139.       nComo = nMsgBox( "¿Cómo desea el filtrado", { "  Por &grupo  ", ;
  140.                        "  Por &concepto  " } )
  141.       if nComo != 0
  142.          if nComo == 1
  143.             BuscaGrupo( .t. )
  144.             if LastKey() != K_ESC
  145.                nGrupo = Grupo->nGRUPO
  146.  
  147.                Apunte->( DbSetFilter( { || Apunte->nGRUPO == nGrupo } ) )
  148.                oBrw:GoTop()
  149.                oBrw:RefreshAll()
  150.  
  151.                oItem:cItem = " &Desfil. "
  152.             endif
  153.          else
  154.             if lInputBox( "Concepto a filtrar:", @ cFiltro )
  155.                cFiltro = Upper( AllTrim( cFiltro ) )
  156.  
  157.                Apunte->( DbSetFilter( { || cFiltro $ Upper( Apunte->cDESC ) } ) )
  158.                oBrw:GoTop()
  159.                oBrw:RefreshAll()
  160.  
  161.                oItem:cItem = " &Desfil. "
  162.             endif
  163.          endif
  164.       endif
  165.    else
  166.       Apunte->( DbClearFilter() )
  167.       oBrW:GoBottom()
  168.       oBrw:RefreshAll()
  169.  
  170.       oItem:cItem = " &Filtrar "
  171.    endif
  172.  
  173. return
  174.  
  175. // ----------------------------------------------------------------------------
  176.  
  177. static proc Eliminar( oBrw )
  178.  
  179.    if nMsgBox( "¿Está seguro de querer eliminar el apunte?", ;
  180.                { "  &Eliminar  ", "  &Cancelar  " } ) == 1
  181.       Config->nINGRESO -= Apunte->nINGRESO
  182.       Config->nGASTO   -= Apunte->nGASTO
  183.  
  184.       if Grupo->( DbSeek( Apunte->nGRUPO, .f. ) )
  185.          Grupo->nINGRESO -= Apunte->nINGRESO
  186.          Grupo->nGASTO   -= Apunte->nGASTO
  187.       endif
  188.  
  189.       Apunte->( DbDelete() )
  190.       Apunte->( DbSkip() )
  191.       oBrw:RefreshAll()
  192.    endif
  193.  
  194. return
  195.  
  196. // ----------------------------------------------------------------------------
  197. // ----------------------------------------------------------------------------
  198.  
  199. static function cGrupoDesc()
  200. return If( Grupo->( DbSeek( Apunte->nGRUPO, .f. ) ), Grupo->cDESC, ;
  201.            PadR( "Grupo inexistente" ,Len( Grupo->cDESC ) ) )
  202.  
  203. // ----------------------------------------------------------------------------
  204.  
  205. static function lDispGrupo()
  206.  
  207.    @ 4, 14 SAY "[" + cGrupoDesc() + "]"
  208.  
  209. return Grupo->( Found() )
  210.  
  211. // ----------------------------------------------------------------------------
  212.  
  213. proc BuscaGrupo( lNoChange )
  214.  
  215.    local oBrw
  216.  
  217.    DEFAULT lNoChange := .f.
  218.  
  219.    SetKey( K_F6, nil )
  220.  
  221.    DEFINE BROWSE oBrw SIZE MaxRow() - 5, 37 ALIAS Grupo ;
  222.           COLSEP " " ;
  223.           TITLE "GRUPOS CONTABLES" ;
  224.           WRAP
  225.       COLUMN "Nº"          DATA Grupo->nGRUPO
  226.       COLUMN "DESCRIPCION" DATA Grupo->cDESC
  227.  
  228.       ON DBLCLICK          DO .t.
  229.       ON KEY K_ENTER       DO .t.
  230.    ENDBROWSE
  231.  
  232. //   if Grupo->( EoF() )
  233.       oBrw:GoTop()
  234. //   endif
  235.  
  236.    ACTIVATE BROWSE oBrw
  237.  
  238.    if ! lNoChange .and. LastKey() != K_ESC
  239.       Apunte->nGRUPO = Grupo->nGRUPO
  240.       lDispGrupo()
  241.    endif
  242.  
  243.    SetKey( K_F6, { || BuscaGrupo() } )
  244.  
  245. return
  246.  
  247. // ----------------------------------------------------------------------------
  248.  
  249. static proc DispFoot()
  250.  
  251.    @ MaxRow(), 64 SAY Transform( Config->nINGRESO - Config->nGASTO, ;
  252.                                  "9,999,999 Ptas" ) ;
  253.                   COLOR Config->cCLRMNU ;
  254.                   ABSOLUTE
  255.  
  256. return
  257.  
  258. // ----------------------------------------------------------------------------
  259.  
  260. static proc LisApunte()
  261.  
  262.    local GetList := {}
  263.    local oWnd, oRep
  264.    local dInicial
  265.    local dFinal  := Date()
  266.  
  267.    Apunte->( DbSetOrder( APUNTE_FECHA ) )
  268.    Apunte->( DbGoTop() )
  269.    dInicial = Apunte->dFECHA
  270.  
  271.    DEFINE WINDOW oWnd SIZE 10, 30 TITLE "Listado de apuntes"
  272.    ACTIVATE WINDOW oWnd
  273.  
  274.    @ 2, 2 SAY "Fecha inicial:" GET dInicial
  275.    @ 3, 2 SAY "Fecha final..:" GET dFinal
  276.  
  277.    READ
  278.  
  279.    if LastKey() != K_ESC
  280.       Apunte->( DbSeek( dInicial ) )
  281.  
  282.       DEFINE REPORT oRep
  283.          HEADER "Contabilidad Personal - Listado de apuntes de: " + ;
  284.                 SubStr( BliSerNum(), 5 )
  285.          HEADER "Entre las fechas: " + DToC( dInicial ) + " y " + DToC( dFinal ) + ;
  286.                 Space( 30 ) + "Pág. #"
  287.          HEADER ""
  288.  
  289.          COLUMN "FECHA"       DATA Apunte->dFECHA
  290.          COLUMN "GRUPO"       DATA cGrupoDesc()
  291.          COLUMN "DESCRIPCION" DATA Apunte->cDESC
  292.          COLUMN "INGRESO"     DATA Transform( Apunte->nINGRESO, "9,999,999" )
  293.          COLUMN "GASTO"       DATA Transform( Apunte->nGASTO, "9,999,999" )
  294.       END REPORT
  295.  
  296.       ACTIVATE REPORT oRep ;
  297.                WHILE ! Apunte->( EoF() ) .and. Apunte->dFECHA <= dFinal ;
  298.                ACTION Apunte->( DbSkip() )
  299.    endif
  300.  
  301.    DEACTIVATE WINDOW oWnd
  302.  
  303. return
  304.  
  305. // ----------------------------------------------------------------------------
  306.